﻿using System;
using RestSharp;
using Spotted.Data.Args;

namespace Spotted.Data.Repositories.Impl
{
    public class RestJsonUserRepository : IUserRepository
    {
        //private const string BaseUrl = "http://192.168.1.101/SpottedWebApi/api";
        //private const string BaseUrl = "http://10.255.17.36:8080/api";
        //private const string BaseUrl = "http://spottedapi.cloudapp.net/api";
        private const string BaseUrl = "http://10.170.132.67/SpottedWebApi/api";

        #region Implementation of IUserRepository

        /// <summary>
        /// 
        /// </summary>
        /// <param name="emailAddress">Email Address for the user, represents their username</param>
        /// <param name="password">The passsword for the user (hashed)</param>
        /// <param name="firstName">The first name for the user</param>
        /// <param name="lastName">The last name for the user</param>
        public void CreateUser(string emailAddress, string password, string firstName, string lastName)
        {
            RestClient client = new RestClient(BaseUrl);
            RestRequest request = new RestRequest("User", Method.POST);
            client.FollowRedirects = true;
            request.RequestFormat = DataFormat.Json;

            request.AddParameter("EmailAddress", emailAddress);
            request.AddParameter("Password", password);
            request.AddParameter("FirstName", firstName);
            request.AddParameter("LastName", lastName);

            client.ExecuteAsync(request, (response, handler) =>
            {
                return;
            });
        }

        public event EventHandler<UserActionCompleteValidEventArgs> CreateUserCompleted;

        #endregion
    }
}
